# #打开D:\code\pycharm-test
# f = open ("D:\\code\\pycharm-test","r",encoding='utf-8')
# print(f"{f.read(10)}")
# #打印1-10数字
# for i in range(1,11):
#     print
# f = open("D:\code\pycharm-test\code_test\bichuan.txt","r",encoding='utf-8')
# print(f"{f.read(10)}")

# 使用原始字符串避免路径问题
file_path = r"D:\code\pycharm-test\code_test\bichuan.txt"


#     # 打开文件并读取前10个字符
# open(file_path, "r", encoding='utf-8') as f:
#     print(f"{f.read(10)}")

# 打开文件并读取前一行
# with open(file_path, "r", encoding='utf-8') as f:
#     print(f.readline())
#     print(f.readline())
#     print(f.readline())
#     #打开D盘文件
#     f = open("D:\code\pycharm-test\code_test\bichuan.txt","r",encoding='utf-8')
#     print(f.readline())

# f = open('bichuan.txt','w')
# f.write('hello world hehe')
# f.flush()
# print(f."{f.read(10)}")

f = open('bill.txt', 'r', encoding='utf-8')
# 打印文件内容
for line in f:
    print(line)

# 将文件指针移到文件开头
# f.seek(0)
# content = f.readlines()
# f.close()
f.seek(0)
contant = f.readlines()
f.close()

new_f = open('bill.txt.bak','a',encoding = 'utf-8')
for line in contant:
    if "测试" not in line:
        new_f.write(line)

#打印备份文件
with open('bill.txt.bak','r',encoding='utf-8') as new_f:
    for line in new_f:
        print(line)
# 打开备份文件
# new_f = open('bill.txt.bak', 'a', encoding='utf-8')
# for line in content:
#     if "测试" not in line:
#         new_f.write(line)
# new_f.close()

# 读取并打印备份文件内容
# with open('bill.txt.bak', 'r', encoding='utf-8') as new_f:
#     for line in new_f:
#         print(line)
